ref(nextjs): Use loader to set RewriteFrames
helper value
#5445
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ref: #5505
In order to work, in the nextjs SDK our server-side
RewriteFrames
integration needs to know the name of the directory into which the app is built. While that information is readily available at build time, it isn't at runtime, so we adjust the webpack config to inject a global variable with the correct value in before the the injectedSentry.init()
call fromsentry.server.config.js
wherever we inject that `Sentry.init().Currently, this is done by creating a temporary file with the relevant code and adding it to the relevant pages'
entry
value along withsentry.server.config.js
. This works, but has its downsides, and is a fair amount of machinery just to add a single line of code.This injects the same line of code using a loader, which is really just a transformation function for the code from matching files. In this case, we're modifying
sentry.server.config.js
itself, so that by the time it's added to various pages' entry points, it already contains the relevant code. Since we don't know what the value will be ahead of time, there's a template, which the loader then populates before injecting the new code.But how is that any less machinery?, you might ask. All of that, still for just one line of code? Honestly, it's not. But in the quest to improve parameterization of transactions names, we're going to be adding a loader in any case. Adding the
RewriteFrames
value thus provides the perfect proof of concept, precisely because it's so simple, letting us get the loader working separate from all of the other changes that work will entail.Notes:
distDir
from retrieval-of-the-value time to storage-of-the-value time, because using a loader necessarily stringifies everything, meaningundefined
was turning into the string'undefined'
, preventing the default from getting picked up.Fixes #4684